#include "ScnsBh1750.c.h"

#if defined(SCNS_BH1750_ENABLE)&&SCNS_BH1750_ENABLE==1

#include "ScnsIic.h"
#include "ScnsMenu.h"
#include "ScnsSmctpExtOscilloscope.h"

ScnsStatus scnsBspBh1750PostInit(ScnsBh1750Enum bh1N)
{
    scnsMenuSetPage(5,"BH1750",NULL);
    scnsMenuAddConstStruct(5,scnsBh1750Result[SCNS_BH1750_1],lux,,SCNS_TYPE_FLOAT);
    return SCNS_STATUS_OK;
}

void scnsBspBh1750ResultUpdate(ScnsBh1750Enum bh1N)
{
#if defined(SCNS_SMCTP_EXT_OSCILLOSCOPE_ENABLE)&&SCNS_SMCTP_EXT_OSCILLOSCOPE_ENABLE==1
    if(scnsMenuCanPageSend(5))
    {
        scnsSmctpExtOscilloscopeSendFloat(
            SCNS_SMCTP_CHANNEL_VISUAL_SCOPE,0,
            scnsBh1750Result[SCNS_BH1750_1].lux
        );
    }
#endif
}

ScnsStatus scnsBspBh1750Write(ScnsBh1750Enum bh1N,const uint8*data,uint8 dataLen)
{
#if defined(SCNS_IIC_ENABLE)&&SCNS_IIC_ENABLE==1
    return scnsIicWriteTick(SCNS_IIC_SOFT_1,0XB8,0,NULL,data,dataLen,64);
#else
    const uint16 ADDR=(addr[0]<<8)|addr[1];
    HAL_I2C_Mem_Write(&hi2c1,0XB8,ADDR,2,data,dataLen,0XFFFFFF);
    return SCNS_STATUS_OK;
#endif
}

ScnsStatus scnsBspBh1750Read(ScnsBh1750Enum bh1N,uint8*data,uint8 dataLen)
{
#if defined(SCNS_IIC_ENABLE)&&SCNS_IIC_ENABLE==1
    return scnsIicReadTick(SCNS_IIC_SOFT_1,0XB8,0,NULL,data,dataLen,64);
#else
    const uint16 ADDR=(addr[0]<<8)|addr[1];
    HAL_I2C_Mem_Read(&hi2c1,0XB8,ADDR,2,data,dataLen,0XFFFFFF);
    return SCNS_STATUS_OK;
#endif
}

#endif
